﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using FCMS.Mvc.Extensions;

namespace FCMS
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //string ext = ".html";
            string ext = string.Empty;

            routes.CreateArea("Admin", "FCMS.MVC.Controllers.Admin",
                routes.MapRoute(
                    null,
                    "Admin/{action}" + ext,
                    new { controller = "Main", action = "Login", id = UrlParameter.Optional }
                ),
                routes.MapRoute(
                    null,
                    "Admin/{controller}/{action}" + ext,
                    new { controller = "Main", action = "Login", id = UrlParameter.Optional }
                ),
                routes.MapRoute(
                    null,
                    "Admin/{controller}/{action}/{id}" + ext,
                    new { controller = "Main", action = "Login", id = UrlParameter.Optional }
                )
            );

            routes.CreateArea("Site", "FCMS.Mvc.Controllers.Site",
                routes.MapRoute(
                    null,
                    "{controller}/{action}" + ext,
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                ),
                routes.MapRoute(
                    null,
                    "{controller}/{action}/{id}" + ext,
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                ),
                //匹配主目录
                routes.MapRoute(
                    null,
                    string.Empty,
                    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                )
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}
